package cn.caplike.demo.consistence.threadpool.and.blockingqueue.core;

import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.ServletContextListener;

/**
 * 在容器启动的时候，注册自定义的 Listener，在监听器中初始化线程池
 *
 * @author LiKe
 * @version 1.0.0
 * @date 2020-03-18 13:15
 */
@Configuration
public class ServletListenerRegistrationConfiguration {

    /**
     * Description: 注册自定义的 Bean<br>
     * Details: 设置监听器，该监听器初始化线程池
     *
     * @return org.springframework.boot.web.servlet.ServletListenerRegistrationBean
     * @author LiKe
     * @date 2020-03-18 13:22:04
     */
    @Bean
    public ServletListenerRegistrationBean<ServletContextListener> registrationBean() {
        ServletListenerRegistrationBean<ServletContextListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<>();
        servletListenerRegistrationBean.setListener(new InitThreadLocalPoolListener());
        return servletListenerRegistrationBean;
    }

}
